{% extends 'front/page/blog/blog_list_base.html' %}

{% block right %}
    <div id="posts-container"></div>
    <div class="text-center mt-3" id="load-more-container">
        <button id="load-more-button" class="btn btn-primary">加载更多</button>
    </div>
{% endblock %}

{% block script %}
   <script>

const postsContainer = document.getElementById('posts-container');
const loadMoreContainer = document.getElementById('load-more-container')
let offset=Number.MAX_SAFE_INTEGER;
let still_load=true

function loadData(){
    if (still_load){
        Fetch('{% block pagination_url %}{% endblock %}','get',{'limit':4,'desc':true,'offset':offset}, res => {
            if (res.status === 'success') {
                res.data.blogs.forEach(pack => {
                    postsContainer.innerHTML += RightItem(post_detail_url.replace('0',pack.pid), '{{ url_for('static',filename='img/default.png') }}', '#', pack.title, pack.author, pack.time, pack.likes,pack.sort);
                });

                if (res.data.offset === offset)
                {
                    still_load=false
                    loadMoreContainer.innerHTML = '<span class="text-muted">没有更多内容了</span>'
                }
                offset = res.data.offset
            }
        });
    }
}


loadData()

Event_('load-more-button','click',event=>{
    loadData()
})

</script>
{% endblock %}
